import type { LoginResult } from '@/types/member'
import { defineStore } from 'pinia'
import { ref, reactive } from 'vue'

export const useMemberStore = defineStore(
        'member',
        () => {
                // 会员信息
                const profile = ref<LoginResult>()

                // 保存会员信息
                const setVipMessage = (val: LoginResult) => {
                        profile.value = val
                }

                // 清理会员信息
                const clearVipMessage = () => {
                        profile.value = undefined
                }
                return {
                        profile,
                        setVipMessage,
                        clearVipMessage
                }
        },
        {
                // 配置持久化
                persist: {
                        // 网页端配置
                        // persist: true,
                        // 调整为兼容多端的API
                        storage: {
                                setItem(key: string, value: any) {
                                        uni.setStorageSync(key, value)
                                },
                                getItem(key: string) {
                                        return uni.getStorageSync(key)
                                },
                        },
                },
        },
)